package cn.kt.mywxdemo.message;

import cn.kt.mywxdemo.token.TokenUtil;
import cn.kt.mywxdemo.utils.HttpUtil;
import org.junit.Test;

/**
 * Created by tao.
 * Date: 2023/3/7 19:26
 * 描述:
 */
public class TestModelMessage {

    //  设置模板行业信息
    //  参考文档：https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
    @Test
    public void testTrade() {
        String url = String.format("https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=%s",
                TokenUtil.getAccessToken());
        String data = "{\n" +
                "    \"industry_id1\":\"1\",\n" +
                "    \"industry_id2\":\"4\"\n" +
                "}";
        //使用post
        System.out.println(HttpUtil.doPost(url, data));
    }

    // 获取设置的模板行业信息
    @Test
    public void testGetTrade() {
        String url = String.format("https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=%s",
                TokenUtil.getAccessToken());
        System.out.println(HttpUtil.doGet(url));
    }

    // 发送模板消息

    @Test
    public void testModelmessage() {
        String url = String.format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s",
                TokenUtil.getAccessToken());
        String data = "{\n" +
                "           \"touser\":\"oJ4VY61KtF_VJL2Zwm_S-4cJnYCw\",\n" +
                "           \"template_id\":\"1_BTU1dlGB9rPWv5JL-Kkivn6OhjAt7wZMGqE9SHaG4\",\n" +
                "           \"data\":{\n" +
                "                   \"first\": {\n" +
                "                       \"value\":\"恭喜你报名成功！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword1\":{\n" +
                "                       \"value\":\"张三\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword2\": {\n" +
                "                       \"value\":\"18899887766\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword3\": {\n" +
                "                       \"value\":\"2023年9月22日\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"keyword4\": {\n" +
                "                       \"value\":\"Java核心基础课程\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   },\n" +
                "                   \"remark\":{\n" +
                "                       \"value\":\"欢迎来到新世界！\",\n" +
                "                       \"color\":\"#173177\"\n" +
                "                   }\n" +
                "           }\n" +
                "       }";
        System.out.println(HttpUtil.doPost(url, data));
    }
}
